﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace ProjectSem3.Admin
{
    public partial class WebForm10 : System.Web.UI.Page
    {
        private DataClassesHeaxlthDataContext dc = new DataClassesHeaxlthDataContext();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                this.DropDownList1.DataSource = this.dc.HospitalInfos;
                this.DropDownList1.DataValueField = "hospitalid";
                this.DropDownList1.DataTextField = "hospitalname";
                this.DropDownList1.DataBind();
            }
        }

        protected void ButtonInsert_Click(object sender, EventArgs e)
        {
            var name = this.dc.policies.Where(a => a.policyname.Equals(this.txtpolicyname.Value)).ToList();
            if (name.Count > 0)
            {
                this.Labelkq.Text = "Policy name already exists";
            }
            else
            {
                string policyname = this.txtpolicyname.Value;
                string policydesc = this.txtpolicydesc.Value;
                decimal amount = Convert.ToDecimal(this.txtamount.Value);
                decimal emi = Convert.ToDecimal(this.txtemi.Value);
                string hospitalid = DropDownList1.SelectedValue.ToString();
                int policyduration = Convert.ToInt32(this.txtPolicyDuration.Value);
                adpolicy(policyname, policydesc, amount, emi, hospitalid, policyduration);
                
            }



        }

        public void adpolicy(string policyname, string policydesc, decimal amount, decimal emi, string hospitalid, int policyduration)
        {
            policy plc = new policy();
            plc.policyname = policyname;
            plc.policydesc = policydesc;
            plc.amount = amount;
            plc.emi = emi;
            plc.hospitalid = Convert.ToInt32(hospitalid);
            plc.policyduration = policyduration;
            this.dc.policies.InsertOnSubmit(plc);
            this.dc.SubmitChanges();
            this.Labelkq.Text = "Insert Successful";
        }
    }
}